package com.rockcent.service.impl;

import com.rockcent.mall.lib.domain.MallCashCouponFlow;
import com.rockcent.mall.lib.domain.enumclass.FundTransactionFlow;
import com.rockcent.mall.lib.repository.MallCashCouponFlowRepository;
import com.rockcent.service.MallCashCouponFlowSrv;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * Created by zhangjh on 2017/1/15.
 */
@Component
public class MallCashCouponFlowSrvImpl implements MallCashCouponFlowSrv {
    @Autowired
    private MallCashCouponFlowRepository mallCashCouponFlowRepository;

    /**
     *
     * @param mallId
     * @param cashCouponId
     * @param operationAmount
     */
    @Override
    public void income(Long mallId, Long cashCouponId, BigDecimal operationAmount) {
        MallCashCouponFlow flow = new MallCashCouponFlow();
        flow.setMallId(mallId);
        flow.setCashCouponId(cashCouponId);
        flow.setOperationAmount(operationAmount);
        flow.setTransactionFlow(FundTransactionFlow.INCOME);
        mallCashCouponFlowRepository.save(flow);
    }

    /**
     *
     * @param mallId
     * @param cashCouponId
     * @param operationAmount
     */
    @Override
    public void expend(Long mallId, Long cashCouponId, BigDecimal operationAmount) {
        MallCashCouponFlow flow = new MallCashCouponFlow();
        flow.setMallId(mallId);
        flow.setCashCouponId(cashCouponId);
        flow.setOperationAmount(operationAmount);
        flow.setTransactionFlow(FundTransactionFlow.EXPEND);
        mallCashCouponFlowRepository.save(flow);
    }
}
